package com.jeesite.modules.st.config;

import com.jeesite.modules.st.pojo.AjaxJson;
import com.jeesite.modules.st.utils.ErrorMsgException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

@Slf4j
@ControllerAdvice
public class GlobalExceptionHandler {

    @ResponseBody
    @ExceptionHandler(ErrorMsgException.class)
    public AjaxJson globalException(ErrorMsgException ex) {
        AjaxJson<String> ajaxJson = new AjaxJson<>();

        ajaxJson.code = -1;
        ajaxJson.data = ex.getMessage();
//        log.info("GlobalExceptionHandler...");

        return ajaxJson;
    }

}